<template>
  <div class="cont-top-box">
    <el-card>
      <el-form label-width="100px">
        <!-- 部门列表 -->
        <el-form-item label="部门">
          <el-checkbox-group v-model="checkDept" style="display:inline-block" @change="checkChange">
            <el-checkbox
              v-for="item in deptList"
              :key="item.id"
              :label="item.id"
            >{{ item.name }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <!-- 社保城市 -->
        <el-form-item label="社保城市">
          <el-checkbox-group v-model="checkCity" style="display:inline-block" @change="checkChange">
            <el-checkbox
              v-for="item in socialCity"
              :key="item.id"
              :label="item.id"
            >{{ item.name }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <!-- 公积金城市 -->
        <el-form-item label="公积金城市">
          <el-checkbox-group v-model="checkProvidentFundCity" style="display:inline-block" @change="checkChange">
            <el-checkbox
              v-for="item in socialCity"
              :key="item.id"
              :label="item.id"
            >{{ item.name }}</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { getDepartments } from '@/api/departments'
import { getCityList } from '@/api/social'

export default {
  data() {
    return {
      checkDept: [],
      checkCity: [],
      checkProvidentFundCity: [],
      deptList: [],
      socialCity: []
    }
  },
  created() {
    // 部门列表
    this.getDepartments()
    // 社保城市
    this.getCityList()
  },
  methods: {
    // 部门列表
    async getDepartments() {
      const { depts } = await getDepartments()
      this.deptList = depts.filter(item => {
        return item.pid !== '-1'
      })
      // console.log(this.deptList)
    },
    // 社保城市
    async getCityList() {
      this.socialCity = await getCityList()
    },
    // 存储多选框打勾的数据
    checkChange() {
      const check = {
        'checkDept': this.checkDept,
        'checkCity': this.checkCity,
        'checkProvidentFundCity': this.checkProvidentFundCity
      }
      // 调用父组件中的方法
      this.$parent.changeSelect && this.$parent.changeSelect(check)
    }

  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.cont-top-box {
  background-color: #ffffff;
  // padding-top: 10px;
  padding-top: -10px;
  padding-bottom: 10px;
}

</style>
